package com.dule.Medic.components;

import org.apache.tapestry5.*;
import org.apache.tapestry5.annotations.*;
import org.apache.tapestry5.ioc.annotations.*;
import org.apache.tapestry5.BindingConstants;

import com.dule.Medic.model.Doctor;
import com.dule.Medic.pages.FirstPage;
import com.dule.Medic.service.DoctorService;

@IncludeStylesheet("context:layout/layout.css")
public class Layout
{
    @SuppressWarnings("unused")
	@Property
    @Parameter(required = true, defaultPrefix = BindingConstants.LITERAL)
    private String title;

    @SuppressWarnings("unused")
	@Property
    @Parameter(defaultPrefix = BindingConstants.LITERAL)
    private String sidebarTitle;

    @SuppressWarnings("unused")
	@Property
    @Parameter(defaultPrefix = BindingConstants.LITERAL)
    private Block sidebar;

    @SessionState      
	@Property    
	private Doctor doctor;     
	private boolean doctorExists; 
    
    @Inject
    private DoctorService doctorService;
    
    public Object onActivate()
    {                  
    	if (doctorExists) 
    	{                   
    		return null;               
    	}             
    	return FirstPage.class;    
    }                  
    
    @OnEvent(component="drLogout")         
    Object drLogOut()
    {         
    	doctor=null;
		return null;
    }      
    
    
    
    @OnEvent(component="deleteDoctor")
    public Object drDelete()
    {
    	doctorService.deleteDoctor(doctor);
    	doctor=null;
    	return this;
    } 
    
    public boolean isDoctorExists() 
    {               
    	return doctorExists;       
    }  
    
    @Property
    private String pageName;

    
    @Inject
    private ComponentResources resources;

    public String getClassForPageName()
    {
      return resources.getPageName().equalsIgnoreCase(pageName)
             ? "current_page_item"
             : null;
    }

    
}
